{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1.显示图像"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x13a8586f790>"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAa4AAAGdCAYAAABKG5eZAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAilklEQVR4nO3df2zV1f3H8deHH711hl5USm+vlgIqoIjVMallOqdUS2eQqvNHw0ZRZAuBRdNpEDMs6pK6MY0TGnSLUA1T0UTKpg4HlR8irQilmTjXUFZbGrhlEHtvW0Zp2vP9Y1+uu3Jv6ZV72572+UhOwufzOefc9z3e+3l57/3cW8cYYwQAgCWG9HUBAABEg+ACAFiF4AIAWIXgAgBYheACAFiF4AIAWIXgAgBYheACAFhlWF8XEAtdXV06fPiwRowYIcdx+rocAECUjDFqaWmR1+vVkCHdv6YaEMF1+PBhpaWl9XUZAIBzdOjQIV1yySXd9hkQwTVixAhJ/73DSUlJfVwNEB9ut7uvSwDi7vT5vDsDIrhOvz2YlJREcAGAxXrycQ8XZwAArEJwAQCsErfgKikp0dixY5WYmKjMzEzt3r272/5vv/22Jk2apMTERE2ZMkXvv/9+vEoDAFgsLsG1fv16FRYWqqioSFVVVcrIyFBOTo6OHj0atv+uXbuUn5+v+fPna9++fcrLy1NeXp72798fj/IAABZz4vGHJDMzM3Xddddp1apVkv77Pau0tDT94he/0OOPP35G//vuu09tbW169913g/uuv/56XXPNNXrppZfOenuBQEBut1t+v5+LMzBg8R1FDAY9OY/H/BXXqVOntHfvXmVnZ399I0OGKDs7WxUVFWHHVFRUhPSXpJycnIj929vbFQgEQhoAYHCIeXAdO3ZMnZ2dSklJCdmfkpIin88XdozP54uqf3Fxsdxud7Dx5WMAGDysvKpw6dKl8vv9wXbo0KG+LgkA0Eti/gXkUaNGaejQoWpqagrZ39TUJI/HE3aMx+OJqr/L5ZLL5YpNwQAAq8T8FVdCQoKmTp2q8vLy4L6uri6Vl5crKysr7JisrKyQ/pK0efPmiP0BAINXXH7yqbCwUAUFBfre976nadOm6YUXXlBbW5seeOABSdLcuXN18cUXq7i4WJL08MMP66abbtJzzz2n22+/XW+++ab27NmjP/zhD/EoDwBgsbgE13333ad///vfevLJJ+Xz+XTNNddo06ZNwQswGhoaQn62fvr06Xr99df1q1/9Sk888YQuv/xylZWV6aqrropHeQAAi8Xle1y9je9xYTDge1wYDPrke1wAAMQTwQUAsArBBQCwCsEFALAKwQUAsArBBQCwCsEFALAKwQUAsArBBQCwCsEFALAKwQUAsArBBQCwCsEFALAKwQUAsArBBQCwCsEFALAKwQUAsArBBQCwCsEFALAKwQUAsArBBQCwCsEFALAKwQUAsArBBQCwCsEFALAKwQUAsArBBQCwCsEFALAKwQUAsArBBQCwCsEFALAKwQUAsArBBQCwCsEFALAKwQUAsErMg6u4uFjXXXedRowYodGjRysvL081NTXdjiktLZXjOCEtMTEx1qUBAAaAmAfX9u3btWjRIlVWVmrz5s3q6OjQbbfdpra2tm7HJSUl6ciRI8FWX18f69IAAAPAsFhPuGnTppDt0tJSjR49Wnv37tUPfvCDiOMcx5HH44l1OQCAASbun3H5/X5J0oUXXthtv9bWVqWnpystLU2zZ8/W559/HrFve3u7AoFASAMADA5xDa6uri498sgj+v73v6+rrroqYr+JEydqzZo12rhxo9atW6euri5Nnz5djY2NYfsXFxfL7XYHW1paWrzuAgCgn3GMMSZeky9cuFB//etftXPnTl1yySU9HtfR0aErrrhC+fn5euaZZ8443t7ervb29uB2IBBQWlqa/H6/kpKSYlI70N84jtPXJQBx15PzeMw/4zpt8eLFevfdd7Vjx46oQkuShg8frmuvvVa1tbVhj7tcLrl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FgbNmzQhx9+qHHjxkU9R2dnpz777DOlpqbGocKeaW1t1cGDByPW0B/W+n+tXbtWo0eP1u233x7VuP6w1pI0btw4eTyekDUNBAL65JNPIq7pt3mOxMPp0Dpw4IC2bNmiiy66KOo5zvZ46w2NjY06fvx4xBr6y3qf9sorr2jq1KnKyMiIemx/WO8QfX11SCy9+eabxuVymdLSUvOPf/zD/OxnPzMjR440Pp/PGGPMT3/6U/P4448H+3/88cdm2LBh5ne/+5354osvTFFRkRk+fLj57LPPeq3mhQsXGrfbbbZt22aOHDkSbCdOnAj2+WbdTz31lPnggw/MwYMHzd69e839999vEhMTzeeff95rdf/yl78027ZtM3V1debjjz822dnZZtSoUebo0aNha+4Pa31aZ2enGTNmjFmyZMkZx/rTWre0tJh9+/aZffv2GUnm+eefN/v27Qtefffss8+akSNHmo0bN5q///3vZvbs2WbcuHHmP//5T3COW265xaxcuTK4fbbnSLzrPnXqlLnjjjvMJZdcYqqrq0Me8+3t7RHrPtvjLd51t7S0mEcffdRUVFSYuro6s2XLFvPd737XXH755ebkyZMR6+7r9T7N7/eb73znO2b16tVh5+iL9T4XAyq4jDFm5cqVZsyYMSYhIcFMmzbNVFZWBo/ddNNNpqCgIKT/W2+9ZSZMmGASEhLM5MmTzXvvvder9UoK29auXRux7kceeSR4H1NSUsyPfvQjU1VV1at133fffSY1NdUkJCSYiy++2Nx3332mtrY2Ys3G9P1an/bBBx8YSaampuaMY/1prbdu3Rr2sXG6vq6uLrNs2TKTkpJiXC6XmTFjxhn3KT093RQVFYXs6+45Eu+66+rqIj7mt27dGrHusz3e4l33iRMnzG233WaSk5PN8OHDTXp6ulmwYMEZAdTf1vu0l19+2Zx33nmmubk57Bx9sd7ngj9rAgCwyoD5jAsAMDgQXAAAqxBcAACrEFwAAKsQXAAAqxBcAACrEFwAAKsQXAAAqxBcAACrEFwAAKsQXAAAqxBcAACr/B8NVeFRAA9emgAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import cv2\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "image = np.zeros(shape=(20,20))\n",
    "image[:, 0:10] = 255\n",
    "\n",
    "plt.imshow(image, cmap='gray')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. ndarray与tensor互转"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([20, 20])\n",
      "torch.Size([1, 20, 20])\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "image_tensor = torch.from_numpy(image)      # 原始为一个二维张量\n",
    "print(image_tensor.shape)\n",
    "image_tensor = image_tensor.unsqueeze(0)     # 升维，参数为在哪个位置加一个维度\n",
    "print(image_tensor.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3. 计算池化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAh8AAAC/CAYAAABe3r4WAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAAARcklEQVR4nO3dX2hT5x/H8U+sNDrXZpRq0kDr6p85NrQDpaWgoBhsc1F0eDFlF1XGBJkXEoasoHX+gaKCFF2xMBD1xrmb9WbgYGW1F9MOnWUMhrSSsYomm4U2bZgR2vO7ULPGttr+evKcnPT9ggeac570fDn9Hvl4Tk6Ox7IsSwAAAIYscLoAAAAwvxA+AACAUYQPAABgFOEDAAAYRfgAAABGET4AAIBRhA8AAGAU4QMAABhF+AAAAEYtdLqAl42Pj+vhw4cqKiqSx+Nxuhy4lGVZGhkZUT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3+y2v12tt3brVunfvnrNFz2P0b3ZwHJhB/9qP3v2Px7Isy4HMAwAA5qmc/MwHAADIX4QPAABgFOEDAAAYRfgAAABGET4AAIBRhA8AAGAU4QMAABhF+AAAAEYRPgAAgFGEDwAAYBThAwAAGEX4AAAARv0PPzLUZ6FFLXgAAAAASUVORK5CYII=",
      "text/plain": [
       "<Figure size 640x480 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from torch import nn\n",
    "\n",
    "max_pool = nn.MaxPool2d(kernel_size=5, stride=1, padding=0)\n",
    "average_pool = nn.AvgPool2d(kernel_size=5, stride=1, padding=0)\n",
    "\n",
    "image_tensor = image_tensor.float()\n",
    "\n",
    "image_max_pool = max_pool(image_tensor)\n",
    "image_avg_pool = average_pool(image_tensor)\n",
    "\n",
    "fig, axs = plt.subplots(1, 3)\n",
    "axs[0].imshow(image, cmap='gray')\n",
    "axs[1].imshow(image_max_pool.squeeze(0).numpy(), cmap='gray')\n",
    "axs[2].imshow(image_avg_pool.squeeze(0).numpy(), cmap='gray')\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "torch",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
